#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#define TXT "file.txt"
int main()
{
  umask(0);
//int fd=open(TXT,O_WRONLY|O_APPEND,0666);
int fd=open(TXT,O_RDONLY);
  if(fd==-1)
{
  printf("fd:%d,errno:%d,strerror(errno):%s\n",fd,errno,strerror(errno));
}
int i=5;
const char* buf="hello world\n";
while(i--)
{
//write(fd,buf,strlen(buf));
}
char arr[1024];
ssize_t ret=read(fd,arr,sizeof(arr)-1);
if(ret>0)
{
  arr[ret]='\0';
  printf("%s",arr);
}
else{
  printf("read fail\n");
}



close(fd);
  return 0;
}




























/*#include <stdio.h>
int main()
{
FILE* fp=fopen("log.txt","a");
if(fp==NULL)
{
  perror("fopen");
  return -1;
}
char const* meg="Please believe yourself";
char buf[100];
int i=3;
while(i--)
{
//fputs(meg,fp);
//fprintf(fp,"%i:%s\n",i,meg);
//sprintf(buf,"%i:%s\n",i,meg);
//snprintf(buf,sizeof(buf),"%i:%s",i,meg);
//fgets(buf,sizeof(buf),fp);
//printf("%s",buf);
fputs(meg,fp);
}
//printf("%s",buf);
fclose(fp);



  return 0;
}*/
